﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Entity.Infrastructure;
using System.Data.Entity;
using Bird.Core.Domain.Projects;

namespace Bird.Data.Test
{
    /// <summary>
    /// Summary description for PersistenceTest
    /// </summary>
    [TestClass]
    public class PersistenceTest
    {


        public PersistenceTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion


        protected BirdObjectContext context;

        EfRepository<Project> projects;

        [TestInitialize]
        public void CreateDatabase()
        {
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
            context = new BirdObjectContext("test");
            context.Database.CreateIfNotExists();
             
            projects = new EfRepository<Project>(context);
        }
      
        protected string GetTestDbName()
        {
            string testDbName = "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + @"\\Nop.Data.Tests.Db.sdf;Persist Security Info=False";
            return testDbName;
        }
        [TestMethod]
        public void InsertProject()
        {

            Project project = new Project()
            {
                CreatorUserId = 0,
                ProjectTitle = "test project",
                ProjectDescription = "this is a test",
                CreateTime = DateTime.Now
            };

            projects.Insert(project);
        }
        [TestMethod]
        public void ShowProjects()
        {
            EfRepository<Project> projects = new EfRepository<Project>(context);
            foreach (var item in projects)
            {
                Console.WriteLine("id:{0} time{1} title:{2}  desc:{3}", item.Id,
                    item.CreateTime,
                    item.ProjectTitle, item.ProjectDescription);
            }
        }
    }
}
